//跳跃游戏 II
class Solution {
public:
    int jump(vector<int>& nums) {
        int n = nums.size();
        int end = 0;
        int maxpos = 0;
        int ret = 0;
        for (int i = 0; i < n - 1; i++) {
            if (maxpos >= i) {
                maxpos = max(maxpos, i + nums[i]);
                if (i == end) {
                    ret++;
                    end = maxpos;
                }
            }
        }
        return ret;
    }
};

//跳跃游戏
class Solution {
public:
    bool canJump(vector<int>& nums) {
        int size = nums[0];
        int n = nums.size();
        for (int i = 0; i <= size; i++) {
            size = max(size, i + nums[i]);
            if (size >= n - 1)
                return true;
        }
        if (size >= n - 1)
            return true;
        return false;
    }
};